home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 Christmas / macformat-045.iso / Shareware Plus / Developers / NGL1.5.0E(fat)DEMO / Cel & Rotate Sample(PPC) / Cel & Rotate Sample.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-19  |  3.2 KB  |  168 lines  |  [TEXT/CWIE]

  1. /*============================================================
  2.  
  3.                     Cel & Rotate sample program
  4.                     
  5. ============================================================*/
  6.  
  7. #include    "N_Library.h"
  8.  
  9. WindowPtr     CreateWindow         (Str255 name);
  10.  
  11.  
  12. #define        WindowSizeX        640
  13. #define        WindowSizeY        480
  14.  
  15. short        NewWindowX;
  16. short        NewWindowY;
  17.  
  18. short        Data_Rsrc = 0;
  19.  
  20. long        total_step = 0;
  21. long        wait;
  22. short        i,r=0;
  23. short        x[80];
  24. short        y[80];
  25. short        sp[80];
  26.  
  27. void main(void)
  28. {
  29.     WindowPtr    window;
  30.  
  31.  
  32.     ToolboxInit();
  33.     ColorCheck();
  34.     HideMenuBar();
  35.     window = CreateWindow("\pN Game Library <Cel & Rotate Sample>");
  36.     N_Window_Set(window,NewWindowX,NewWindowY,WindowSizeX,WindowSizeY);
  37.     Open_Resource_File(128,1,&Data_Rsrc);
  38.     N_Sp_Make(640,480);                                                //setup for sprite
  39.     N_Cel_Make(200000);                                                //setup for cel
  40.     HideCursor();
  41.     N_Pict_Draw(128,0,0,(GrafPtr)Main_Window,true);
  42.     N_Sprite_Set(200,0,32,32,0,1,1,1);                                    //set Sprite 0(rotation mode)
  43.     N_Sprite_Set(201,1,32,32,0,1,1,0);                                    //set Sprite 1
  44.     N_Sprite_Set(202,2,32,32,0,1,1,0);                                    //set sprite 2
  45.     N_Pict_Draw(130,0,0,(GrafPtr)Main_Window,true);    
  46.     Close_Resource_File(&Data_Rsrc);
  47.  
  48.     for (i=0;i!=50;i++)                                                    //make random position
  49.     {
  50.         x[i] = GetRandom(0,640);
  51.         y[i] = GetRandom(0,480+240)-120;
  52.         sp[i] = GetRandom(1,5)*2;
  53.     }
  54.  
  55.     do
  56.     {
  57.         total_step++;
  58.  
  59.         N_Sp_Put(0x80000000+1,(long)GetRandom(0,640)/32*32,(long)GetRandom(0,480)/32*32);    //draw background
  60.         N_Sp_Put(0x80000000+2,(long)GetRandom(0,640)/32*32,(long)GetRandom(0,480)/32*32);
  61.  
  62.         if (total_step<128)                                                //move
  63.         {
  64.             for (i=0;i!=50;i++)
  65.             {
  66.     
  67.     
  68.                 N_Cel_Put(i,0x80000000,x[i],y[i]);
  69.     
  70.                 x[i] = x[i] + sp[i];
  71.  
  72.                 if (x[i]>640)
  73.                 {
  74.                     x[i] = -32;
  75.                     y[i] = GetRandom(0,480+240)-120;
  76.                 }
  77.             }
  78.         }
  79.  
  80.         if (total_step>=128 && total_step<256)                                //rotation
  81.         {
  82.             for (i=0;i!=50;i++)
  83.             {
  84.     
  85.  
  86.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],320,240,r);
  87.             }
  88.             r-=8;
  89.         }
  90.  
  91.         if (total_step>=256 && total_step<384)                                //rotation & move 1
  92.         {
  93.             for (i=0;i!=50;i++)
  94.             {
  95.     
  96.  
  97.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],320,240,r);
  98.  
  99.                 x[i] = x[i] + sp[i];
  100.  
  101.                 if (x[i]>640)
  102.                 {
  103.                     x[i] = -32;
  104.                     y[i] = GetRandom(0,480+240)-120;
  105.                 }
  106.     
  107.             }
  108.             r+=8;
  109.         }
  110.  
  111.         if (total_step>=384 && total_step<512)                                //rotation & move 2
  112.         {
  113.             for (i=0;i!=50;i++)
  114.             {
  115.     
  116.     
  117.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],x[i]+16,y[i]+16,r);
  118.                 x[i] = x[i] + sp[i];
  119.                 
  120.                 if (x[i]>640)
  121.                 {
  122.                     x[i] = -32;
  123.                     y[i] = GetRandom(0,480+240)-120;
  124.                 }
  125.             }
  126.  
  127.             r-=16;
  128.         }
  129.  
  130.  
  131.         if (total_step == 511)
  132.         {
  133.             total_step =0;
  134.             r = 0;
  135.         }
  136.         
  137.         N_Cel_Loop(0,0);
  138.     }
  139.         while (!Button());
  140.  
  141.         ShowMenuBar();
  142.         ShowCursor();
  143.         ColorRevert();
  144. }
  145.  
  146.  
  147.  
  148. WindowPtr CreateWindow (Str255 name)
  149. {
  150.     WindowPtr    window;
  151.     short        centerX,centerY;
  152.     short        windowWidth,windowHeight;
  153.  
  154.  
  155.     window = GetNewWindow (128,nil,(WindowPtr)-1L );
  156.     centerX  = (qd.screenBits.bounds.right -qd.screenBits.bounds.left)/2;
  157.     centerY  = (qd.screenBits.bounds.bottom -qd.screenBits.bounds.top)/2;
  158.     SetWTitle(window,name);
  159.     MoveWindow(window,NewWindowX=centerX-(WindowSizeX/2),NewWindowY=centerY-(WindowSizeY/2),false);
  160.     SizeWindow(window,WindowSizeX,WindowSizeY,TRUE);
  161.  
  162.     ShowWindow(window);
  163.     SetPort((GrafPtr)window );
  164.     return (WindowPtr)window;
  165. }
  166.     
  167.  
  168.